home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / viewers / pcshow / ega.asm < prev    next >
Assembly Source File  |  1991-07-01  |  15KB  |  457 lines

  1. ;
  2. ;  EGA GRAPHICS DRIVER 
  3. ;
  4. ;  supports raster graphics on the Enhanced Adapter
  5. ;
  6. ;      Tim Krauskopf               Spring 1986
  7. ;
  8. ;  National Center for Supercomputing Applications
  9. ;  605 E. Springfield
  10. ;  Champaign, IL 61820
  11. ;  (217) 244-0074
  12. ;
  13. ;
  14.         TITLE   EGA GRAPHICS RASTER DRIVER
  15.         NAME    EGA
  16.         INCLUDE DOS.MAC
  17.         SETX
  18. ;
  19. ;  Define where the registers are
  20. ;
  21. SEQ        EQU        03C4H
  22. MAPREG    EQU        2
  23. MAPMASK    EQU        03C5H
  24. GCHIP    EQU        03CEH
  25. DRREG   EQU     3
  26. MODEREG EQU     5
  27. BITREG    EQU        8
  28. BITMASK    EQU        03CFH
  29. ;
  30.         DSEG
  31. FLAG    DB      0            ; HAVE WE SET REGS UP
  32.         ENDDS
  33.  
  34.         PSEG
  35.         PUBLIC  EGALINE;,EGALINE2,EGALINEA,EGAPOINT
  36.         PUBLIC    INITEGA,RESETEGA,EGAPAL
  37. ;******************************************************************
  38. ;  INITEGA
  39. ;    use the BIOS to set mode 10 on the EGA board
  40. ;
  41. INITEGA    PROC    FAR
  42.         MOV        AX,10H            ; set to hi-res mode for EGA
  43.         INT     10h                ; video
  44.         RET
  45. INITEGA    ENDP
  46.  
  47. RESETEGA    PROC    FAR
  48.         MOV        AX,3            ; set to color character mode
  49.         INT        10h
  50.         RET
  51. RESETEGA    ENDP
  52.  
  53. ;*******************************************************************
  54. ;  PALETTE 
  55. ;     set one element of the EGA's palette select
  56. ;
  57. ;  usage:  egapal(reg,setting);
  58. ;             reg (0-15)        EGA's palette regs
  59. ;             setting            one byte, what to write there
  60. ;
  61. EGAPAL    PROC    FAR
  62.         PUSH    BP
  63.         MOV        BP,SP
  64.         MOV        BL,[BP+X]        ; register #
  65.         MOV        BH,[BP+X+2]        ; value
  66.         MOV        AX,01000H        ; set palette element
  67.         INT        10h
  68.         POP        BP
  69.         RET
  70. EGAPAL    ENDP
  71.  
  72. ifdef QAK
  73. ;*****************************************************************
  74. ;  Puts an absolute pixel in the given color
  75. ;
  76. ;   usage:   egapoint(x,y,color,table)
  77. ;            x,y = point location
  78. ;            color = integer color number  0 to 255
  79. ;            table = translation table of 256 bytes for XLAT
  80. ;
  81. ;   BUG:  will only write on black background, see egaline for
  82. ;         clearing all four planes before writing to specified planes
  83. ;         in that color
  84. ;
  85. EGAPOINT    PROC    FAR
  86.         PUSH    BP
  87.         MOV        BP,SP
  88.         MOV     AL,FLAG  
  89.         OR      AL,AL
  90.         JNZ     NOSETUP
  91.         CALL    SETUPG            ; set up the mask regs
  92.         MOV     FLAG,1            ; set the flag
  93. NOSETUP:
  94.         MOV     CX,[BP+X+8]       ; get segment of transtable
  95.         MOV     BX,[BP+X+6]       ; get offset of transtable
  96.         MOV        AX,[BP+X+4]       ; get the color param = 3rd param
  97.         PUSH DS
  98.         MOV  DS,CX                ; set ds for the transtable
  99.         XLATB                     ; pick up translated color
  100.         POP     DS
  101.         MOV        DX,MAPMASK
  102.         OUT        DX,AL             ; set the mask to this color
  103.         MOV        AX,0A000H
  104.         MOV     ES,AX             ; set for addressing
  105.         MOV        AX,[BP+X+2]       ; get y value 0 < y < 350
  106.         MOV        BX,80
  107.         MUL     BX                ; multiply by 80 bytes/line
  108.         MOV     DI,AX             ; put in DI
  109.         MOV     AX,[BP+X]         ; get x value 0 < x < 640
  110.         MOV     BX,AX             ; save it
  111.         MOV     CL,3
  112.         SHR     AX,CL             ; divide by 8
  113.         ADD     DI,AX             ; add it to di = byte offset
  114.         ;
  115.         MOV     CX,BX
  116.         AND     CX,0007H          ; save only the right three bits
  117.         MOV     BL,80H            ; here's a bit
  118.         SHR        BL,CL             ; move it over some
  119.         MOV     DX,BITMASK        ; set the mask
  120.         MOV     AL,BL             
  121.         OUT     DX,AL             ;  send it
  122. ;
  123.         MOV        AL,0FFH           ; set all bits
  124.         MOV        AH,ES:[DI]        ; latch the bytes
  125.         STOSB                     ; place that bit on bit mask
  126.  
  127.         
  128.         POP        BP
  129.         RET
  130. EGAPOINT    ENDP
  131. endif
  132.  
  133. SETUPG:
  134.         MOV        DX,GCHIP
  135.         MOV        AL,MODEREG
  136.         OUT        DX,AL             ; choose write mode 0
  137.         INC        DX
  138.         MOV        AL,0
  139.         OUT        DX,AL             ; clear mode reg to 0
  140.         DEC     DX
  141.         MOV        AL,DRREG          ; clear function select = Replace
  142.         OUT        DX,AL
  143.         INC     DX
  144.         MOV        AL,0h             ; clear all
  145.         OUT        DX,AL
  146. ;
  147.         MOV        AL,MAPREG         ; want to access mapreg from 
  148.         MOV        DX,SEQ            ; sequencer set of regs
  149.         OUT        DX,AL
  150.         MOV        AL,BITREG         ; want to access bitreg from
  151.         MOV     DX,GCHIP          ; graphics chip's regs
  152.         OUT        DX,AL
  153.         MOV        DX,BITMASK        ; set up the bitmask = no masking
  154.         MOV        AL,0FFH           ; all bits on
  155.         OUT        DX,AL
  156.         RET
  157. ;
  158. ;**************************************************************************
  159. ;  EGALINE
  160. ;
  161. ;   Write a stream of colors (represented by bytes) to the EGA, with 
  162. ;   a translation table for the EGA color map.
  163. ;
  164. ;   Usage:     egaline(x,y,colorbuffer,n,table,xoff)
  165. ;            x,y = point to start line
  166. ;            colorbuffer = 4 byte pointer to stream of 
  167. ;            n    bytes.
  168. ;            table  = 4 byte pointer to translation table, 256 bytes
  169. ;                      long for XLAT instruction
  170. ;             xoff    = offset into the line to be sent to the screen
  171.  
  172. EGALINE    PROC    FAR
  173.         PUSH    BP
  174.         MOV        BP,SP
  175.         MOV     AL,FLAG  
  176.         OR      AL,AL
  177.         JNZ     NOSETUP2
  178.         CALL    SETUPG            ; set up the mask regs
  179.         MOV     FLAG,1            ; set the flag
  180. NOSETUP2:
  181.         PUSH    DS                ; save our ds
  182.         MOV     AX,[BP+X+6]       ; get color table segment
  183.         MOV     DS,AX             ; use it now
  184.  
  185.         MOV        AX,0A000H
  186.         MOV     ES,AX             ; set for addressing
  187.         MOV        AX,[BP+X+14]; GET THE X OFFSET INTO THE ARRAY
  188.         CMP        AX,0        ; CHECK FOR NEGATIVE OFFSET
  189.         JGE        OKSIGN        ; JUMP AROUND FIXING THE WINDOW IF POSITIVE
  190.         NEG        AX            ; TAKE THE OPPOSITE VALUE
  191.         ADD        AX,[BP+X]    ; AND ADD IT TO THE POSITION ON THE SCREEN
  192.         MOV        [BP+X],AX    ; AND RE-STORE THE POSITION
  193.         MOV        AX,[BP+X+8]    ; GET THE NEGATIVE OFFSET AGAIN
  194.         ADD        AX,[BP+X+8]    ; REDUCE THE NUMBER OF BYTES TO COPY TO THE SCREEN
  195.         MOV        [BP+X+8],AX    ; AND STORE THE NUMBER OF BYTES AGAIN
  196. OKSIGN:
  197.         MOV        [BP+X+14],AX; PUT THE OFFSET BACK
  198. ;
  199.         MOV        AX,[BP+X+2]       ; get y value 0 < y < 350
  200.         MOV        BX,80
  201.         MUL     BX                ; multiply by 80 bytes/line
  202.         MOV     DI,AX             ; put in DI
  203.         MOV     AX,[BP+X]         ; get x value 0 < x < 640
  204.         MOV     BX,AX             ; save it
  205.         MOV     CL,3
  206.         SHR     AX,CL             ; divide by 8
  207.         ADD     DI,AX             ; add it to di = byte offset
  208.         ;
  209.         MOV     CX,BX
  210.         AND     CX,0007H          ; save only the right three bits
  211.         MOV     BL,080H           ; here's a bit
  212.         ROR        BL,CL             ; move it over some
  213. ;
  214. ;  At this point, bl has the bit mask for the first bit in the line
  215. ;  Keep rotating it and set the mask for each bit to write
  216. ;
  217.         MOV     CX,[BP+X+8]       ; get count of bytes
  218.         CMP        CX,0              ; CHECK FOR ZERO BYTES
  219.         JL        LINEDONE          ; JUMP TO THE END OF THE ROUTINE
  220.         MOV     SI,[BP+X+4]       ; where to get the new colors
  221.         ADD     SI,[BP+X+14]      ; add in the x offset into the line
  222.  
  223.         MOV     AH,BL             ; keep bit rotation in ah
  224.         MOV     DX,[BP+X+12]      ; get segment of transtable
  225.         MOV     BX,[BP+X+10]      ; get offset of transtable
  226.  
  227. NEXTBIT:
  228.         LODSB                     ; get the next color to al
  229.         PUSH DS
  230.         MOV  DS,DX                ; set ds for the transtable
  231.         XLATB                     ; pick up translated color to al
  232.         PUSH AX                   ; need it later
  233.  
  234.         MOV     DX,BITMASK        ; set the bitmask to current rotation
  235.         MOV     AL,AH
  236.         OUT     DX,AL             ;  send it
  237.  
  238.         MOV        DX,MAPMASK
  239.         MOV     AL,0FH            ; open all bit planes
  240.         OUT        DX,AL             ; send it
  241.  
  242.         MOV        AL,ES:[DI]        ; latch the whole set of bytes
  243.         MOV     BYTE PTR ES:[DI],0H  ; clear all four planes to 0 at this bit
  244.         POP        AX                ; get real color back
  245.         OUT        DX,AL              ; send it to set the color planes
  246.  
  247.         MOV     DX,DS             ;  recover what was in dx
  248.         POP     DS
  249. ;
  250.         MOV        AL,0FFH           ; set all bits
  251.         CMP     AH,01             ; see if we are at end of byte
  252.         JZ      INCSTORE
  253.  
  254. NONINC:
  255.         MOV     ES:[DI],AL        ; write the bit from bitmask
  256.         ROR     AH,1              ; rotate me
  257.         LOOP    NEXTBIT          ; go back for next one
  258.         JMP     LINEDONE
  259.  
  260. INCSTORE:
  261.         STOSB                     ; place that bit on bit mask and next byte
  262.         ROR     AH,1              ; rotate me
  263.         LOOP    NEXTBIT
  264.  
  265. LINEDONE:
  266.         POP     DS        
  267.         POP        BP
  268.         RET
  269. EGALINE    ENDP
  270.  
  271. ifdef QAK        
  272. EGALINE2    PROC    FAR
  273.         PUSH    BP
  274.         MOV        BP,SP
  275.         MOV     AL,FLAG  
  276.         OR      AL,AL
  277.         JNZ     NO2SETUP2
  278.         CALL    SETUPG            ; set up the mask regs
  279.         MOV     FLAG,1            ; set the flag
  280. NO2SETUP2:
  281.         PUSH    DS                ; save our ds
  282.         MOV     AX,[BP+X+6]       ; get color table segment
  283.         MOV     DS,AX             ; use it now
  284.  
  285.         MOV        AX,0A000H
  286.         MOV     ES,AX             ; set for addressing
  287.         MOV        AX,[BP+X+2]       ; get y value 0 < y < 350
  288.         MOV        BX,80
  289.         MUL     BX                ; multiply by 80 bytes/line
  290.         MOV     DI,AX             ; put in DI
  291.         MOV     AX,[BP+X]         ; get x value 0 < x < 640
  292.         MOV     BX,AX             ; save it
  293.         MOV     CL,3
  294.         SHR     AX,CL             ; divide by 8
  295.         ADD     DI,AX             ; add it to di = byte offset
  296.         ;
  297.         MOV     CX,BX
  298.         AND     CX,0007H          ; save only the right three bits
  299.         MOV     BL,0C0H           ; here's 2 bits
  300.         ROR        BL,CL             ; move it over some
  301. ;
  302. ;  At this point, bl has the bit mask for the first bit in the line
  303. ;  Keep rotating it and set the mask for each bit to write
  304. ;
  305.         MOV     CX,[BP+X+8]       ; get count of bytes
  306.         MOV     SI,[BP+X+4]       ; where to get the new colors
  307.  
  308.         MOV     AH,BL             ; keep bit rotation in ah
  309.         MOV     DX,[BP+X+12]      ; get segment of transtable
  310.         MOV     BX,[BP+X+10]      ; get offset of transtable
  311.  
  312. NEXT2BIT:
  313.         LODSB                     ; get the next color to al
  314.         PUSH DS
  315.         MOV  DS,DX                ; set ds for the transtable
  316.         XLATB                     ; pick up translated color to al
  317.         PUSH AX                   ; need it later
  318.  
  319.         MOV     DX,BITMASK        ; set the bitmask to current rotation
  320.         MOV     AL,AH
  321.         OUT     DX,AL             ;  send it
  322.  
  323.         MOV        DX,MAPMASK
  324.         MOV     AL,0FH            ; open all bit planes
  325.         OUT        DX,AL             ; send it
  326.  
  327.         MOV        AL,ES:[DI]        ; latch the whole set of bytes
  328.         MOV     BYTE PTR ES:[DI],0H  ; clear all four planes to 0 at this bit
  329.         POP        AX                ; get real color back
  330.         OUT        DX,AL              ; send it to set the color planes
  331.  
  332.         MOV     DX,DS             ;  recover what was in dx
  333.         POP     DS
  334. ;
  335.         MOV        AL,0FFH           ; set all bits
  336.         CMP     AH,03             ; see if we are at end of byte
  337.         JZ      INC2STORE
  338.  
  339. NON2INC:
  340.         MOV     ES:[DI],AL        ; write the bit from bitmask
  341.         ROR     AH,1              ; rotate me
  342.         ROR     AH,1              ; rotate me
  343.         LOOP    NEXT2BIT          ; go back for next one
  344.         JMP     LINE2DONE
  345.  
  346. INC2STORE:
  347.         STOSB                     ; place that bit on bit mask and next byte
  348.         ROR     AH,1              ; rotate me
  349.         ROR     AH,1              ; again
  350.         LOOP    NEXT2BIT
  351.  
  352. LINE2DONE:
  353.         POP     DS        
  354.         POP        BP
  355.         RET
  356. EGALINE2    ENDP
  357.  
  358. ;**************************************************************************
  359. ;  EGALINEA
  360. ;
  361. ;   Write a stream of colors (represented by bytes) to the EGA, with 
  362. ;   a translation table for the EGA color map.  This one includes arbitrary
  363. ;   width expansion.
  364. ;
  365. ;   Usage:     egalinea(x,y,colorbuffer,n,table,expansion)
  366. ;            x,y = point to start line
  367. ;            colorbuffer = 4 byte pointer to stream of 
  368. ;            n    bytes.
  369. ;            table  = 4 byte pointer to translation table, 256 bytes
  370. ;                      long for XLAT instruction
  371. ;            expansion = how much horizontal pixel expansion you want
  372. ;
  373.  
  374. EGALINEA    PROC    FAR
  375.         PUSH    BP
  376.         MOV        BP,SP
  377.         MOV     AL,FLAG  
  378.         OR      AL,AL
  379.         JNZ     NOSETA
  380.         CALL    SETUPG            ; set up the mask regs
  381.         MOV     FLAG,1            ; set the flag
  382. NOSETA:
  383.         PUSH    DS                ; save our ds
  384.         MOV     AX,[BP+X+6]       ; get color table segment
  385.         MOV     DS,AX             ; use it now
  386.  
  387.         MOV        AX,0A000H
  388.         MOV     ES,AX             ; set for addressing
  389.         MOV        AX,[BP+X+2]       ; get y value 0 < y < 350
  390.         MOV        BX,80
  391.         MUL     BX                ; multiply by 80 bytes/line
  392.         MOV     DI,AX             ; put in DI
  393.  
  394.         MOV     AX,[BP+X]         ; get x value 0 < x < 640
  395.         MOV     BX,AX             ; save it
  396.         MOV     CL,3
  397.         SHR     AX,CL             ; divide by 8
  398.         ADD     DI,AX             ; add it to di = byte offset
  399.         ;
  400.         MOV     CX,BX
  401.         AND     CX,0007H          ; save only the right three bits
  402.         MOV     BL,080H           ; here's a bit
  403.         ROR        BL,CL             ; move it over some
  404. ;
  405. ;  At this point, bl has the bit mask for the first bit in the line
  406. ;  Keep rotating it and set the mask for each bit to write
  407. ;
  408.         MOV     SI,[BP+X+4]       ; where to get the new colors
  409.  
  410.         MOV     AH,BL             ; keep bit rotation in ah
  411.         MOV     DX,[BP+X+12]      ; get segment of transtable
  412.         MOV     BX,[BP+X+10]      ; get offset of transtable
  413.  
  414. NEXTBYTE:
  415.         MOV        CX,[BP+X+14]      ; pixel expansion number
  416.         LODSB                     ; the next color to write
  417.         PUSH     DS
  418.          MOV        DS,DX             ; get the seg for xlat from dx
  419.         XLATB                      ; color translation
  420.         MOV        [BP+X],AL         ; used as a local var for translated color
  421.  
  422. NEXTP:
  423.         MOV     DX,BITMASK        ; set the bitmask to current rotation
  424.         MOV     AL,AH
  425.         OUT     DX,AL             ;  send it
  426.  
  427.         MOV        DX,MAPMASK
  428.         MOV     AL,0FH            ; open all bit planes
  429.         OUT        DX,AL             ; send it
  430.  
  431.         MOV        AL,ES:[DI]        ; latch the whole set of bytes
  432.         MOV     BYTE PTR ES:[DI],0H  ; clear all four planes to 0 at this bit
  433.         MOV        AL,[BP+X]         ; get real color from local var
  434.         OUT        DX,AL              ; send it to set the color planes
  435. ;
  436.         MOV        AL,0FFH           ; set all bits
  437.         MOV        ES:[DI],AL          ; set it!
  438.         CMP     AH,01             ; see if we are at end of byte
  439.         JNZ     SAMEBYTE
  440.         INC        DI                ; get us to the next destination byte
  441. SAMEBYTE:
  442.         ROR     AH,1              ; rotate me
  443.         LOOP    NEXTP             ; go back for next one
  444.  
  445.         MOV        DX,DS             ; reset xlat segment into dx
  446.         POP        DS                ; get data input seg back
  447.         DEC        WORD PTR [BP+X+8] ; number of data points
  448.         JNZ        NEXTBYTE          ; do another, if necessary
  449.  
  450.         POP     DS        
  451.         POP        BP
  452.         RET
  453. EGALINEA    ENDP
  454. endif
  455.         ENDPS
  456.         END
  457.